<template>
    <el-card>
        <el-card>
            <el-row class="form-row">
                <el-form :model="filters" label-position="right" inline ref="formInline">
                    <el-form-item label="小区名称">
                        <div class="filters-input" style="width: 250px;">
                            <el-select v-model="filters.housingId" :clearable="true" placeholder="请选择小区">
                                <el-option v-for="item in housingList" :value="item.id" :key="item.id" :label="item.name"></el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="短信类型">
                        <div class="filters-input">
                            <el-select v-model="filters.type" :clearable="true" placeholder="请选择短信类型">
                                <el-option value="1" key="1" label="验证码"></el-option>
                                <el-option value="2" key="2" label="账单催收"></el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="ios-search" @click="handleQuery('formInline')">搜索</el-button>
                    </el-form-item>
                </el-form>
            </el-row>
            <el-table stripe border :loading="tableLoading" :data="tableData" ref="table"
                      style="width: 100%">
                <template slot="empty">暂无数据</template>
                <el-table-column label="小区名称" prop="housingName"></el-table-column>
                <el-table-column label="组团" prop="groupName"></el-table-column>
                <el-table-column label="楼栋" prop="building"></el-table-column>
                <el-table-column label="单元" prop="unit"></el-table-column>
                <el-table-column label="房间号" prop="room"></el-table-column>
                <el-table-column label="发送手机号" prop="phone"></el-table-column>
                <el-table-column label="短信类型" prop="type" :formatter="formatterPayType"></el-table-column>
            </el-table>
            <Page style="margin: 10px 0;" :total="pageTotal" :current="pageNum" :page-size="pageSize" show-total
                  id="lyPage"
                  show-sizer show-elevator @on-change="handlePage" @on-page-size-change='handlePageSize'>
            </Page>
        </el-card>
    </el-card>
</template>


<script>

    export default {
        data() {
            return {
                housingList:[],
                //查询条件
                filters: {},
                //页码
                pageNum: 1,
                //每页数量
                pageSize: 10,
                //总数
                pageTotal: 0,
                tableData: [],
                //表单提交状态
                tableLoading: false,
            }
        },
        created: function () {
            this.loadData();
            this.gethousingList();
        },
        methods: {
            gethousingList(){
                this.postRequest("/api/housing/getHousingByLogin").then(res => {
                    this.housingList = res;
                });
            },
            //加载数据
            loadData: function () {
                if (this.tableLoading) return;
                this.tableLoading = true;
                let params = this.filters;
                params.pageNum = this.pageNum;
                params.pageSize = this.pageSize;
                //与后台交换数据
                this.postRequest("/api/smsInfo/loadData", params).then(res => {
                    console.log(res)
                    this.tableLoading = false;
                    if (res.code == 20000) {
                        this.tableData = res.data.list;
                        this.pageTotal = res.data.total;
                    } else {
                        this.tableData = [];
                        this.$Message.error({
                            content: res.message,
                            duration: 5
                        });
                    }
                });
            },
            //短信类型
            formatterPayType(row, column) {
                if (row.type == 1) {
                    return "验证码";
                } else if (row.type == 2) {
                    return "账单催收";
                }
            },
            //查询
            handleQuery() {
                this.loadData();
            },
            handlePage(value) {
                this.pageNum = value;
                this.loadData();
            },
            handlePageSize(value) {
                this.pageSize = value;
                this.loadData();
            },
        }
    };
</script>
<style lang="less" scoped>
    #pop {
        width: 780px;
        height: 600px;
        display: none;
        position: fixed;
        z-index: 10;
        top: 10%;
        left: 50%;
        margin-left: -390px;
    }
</style>
